package util;

import org.hibernate.Session;
import org.hibernate.Transaction;

public class GenericDAO<T> {
    
    private Session sessao;
    private Transaction transacao;
    
    public void salvar(T o){
        sessao = HibernateUtil.getSessionFactory()
                .openSession();
        transacao = sessao.beginTransaction();
        sessao.save(o);
        transacao.commit();
        sessao.close();
    }
    
    public void atualizar(T o){
        sessao = HibernateUtil.getSessionFactory()
                .openSession();
        transacao = sessao.beginTransaction();
        sessao.update(o);
        transacao.commit();
        sessao.close();
    }
    
    public void deletar(T o){
        sessao = HibernateUtil.getSessionFactory()
                .openSession();
        transacao = sessao.beginTransaction();
        sessao.delete(o);
        transacao.commit();
        sessao.close();
    }
}
